//Open messageBox window

//messageStatus0 saves return value that type is 0;messageStatus1 saves return value that type is 1;
//return "OK" when click button "OK" ;return "Cancel" when click button "Cancel" ;return "Esc" when click image "X" ;
var messageStatus0=null;
var messageStatus1=null;
var messageStatus2=null;
//messageBox handle
var openWinMessageBox;
//return result from function messageBox
var resWinMessageBox ;
//check handle "openWinMessageBox" exist or not
var messageBoxExistFlag = false;
//save temporary value when click button.
var resArray ;
//
var intervalHandle ;
//
var messageBox_strOk = 'OK';
var messageBox_strCancel = 'Cancel';
var messageBox_strContinue = 'Continue';

function showMessageBox( _title, _messageContent, _type,_boxType, _callbackFuncName, _width, _height)
{
	openWinMessageBox = messageBox( _title, _messageContent, _type,_boxType, _callbackFuncName, _width, _height);
}

function messageBox( _title, _messageContent, _messageBoxType,_boxType, _callbackFuncName, _width, _height)
{
		if(_messageBoxType == 1){
		 
			resWinMessageBox = new openProductDetail( _title, _messageContent, _messageBoxType, _callbackFuncName, _width, _height);
		    resWinMessageBox.show();		 
		 
		}else{
			resWinMessageBox = new messageDialog( _title, _messageContent, _messageBoxType, _callbackFuncName, _width, _height);
		    resWinMessageBox.show();
		}
		return resWinMessageBox;
}
function closeMessage(){
	openWinMessageBox.reset();	
	var messageBox=$('messageBoxCase');
	messageBox.parentNode.removeChild(messageBox);
	var mask=$('mask');
	mask.parentNode.removeChild(mask);
}
function closeMessageBoxBase(obj,type,funcName)
{
	messageStatus0=null;
	messageStatus1=null;
	messageStatus2=null;
	if(type==0){
		messageStatus0 = obj.id;
	}
	else if(type==1){
		messageStatus1 = obj.id;
	}
	else if(type==2){
		messageStatus2 = obj.id;
	}

	if(funcName!=null && funcName!="" && funcName!="undefined"){
		eval(funcName+'()');
		document.getElementById('mask').style.display='none';
	}else{
		openWinMessageBox.reset();	
	}
	var messageBox=$('messageBoxCase');
	messageBox.parentNode.removeChild(messageBox);
	var mask=$('mask');
	mask.parentNode.removeChild(mask);	
}
/* begin by open product */
function openProductDetail( _title, _messageContent, _messageBoxType, _callbackFuncName, _width, _height)
{
    var title ;
    var messageContent ;
	var type ;
	var callbackFuncName ;
    var sFunc ;
    var sBody ;
    var sBox ;
    var strMask ;
	title = "&nbsp;"+_title;
	messageContent = _messageContent;
	type = _messageBoxType;
	callbackFuncName = _callbackFuncName;
	var titleLen = title.length;
	var messageLen = messageContent.length;
    var width = messageLen*10<500 ? messageLen*10<250 ? 250 : messageLen*10 : 500 ;
    var height = parseInt(messageLen/10)+100 ;
    if(_width!=null && _width!="")
    	width = _width;
    if(_height!=null && _height!="")
    	height = _height;
    //var path = "/mianfeipaibao/app/webroot/img/";
    var path = "/img/";
	var strClose = '<input type="image" id="messageBoxClose" value="Esc" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" src="'+path+'msg_box_cancel.gif" border="0" width="15" height="15"  align="absmiddle" />';

    this.strBody = '\
    <table id="messageBodyBox" width="100%" border="0" cellspacing="0" cellpadding="0" class="details_box_bg">\
	  <tr>\
	    <td height="23" align="right" style="padding:5px 5px;"><a href=""><a href="javascript:closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');"><img src="'+path+'msg_box_cancel.gif" border="0" /></a></td>\
	  </tr>\
	  <tr>\
	    <td height="130" id="messageMsg" align="center">&nbsp;</td>\
	  </tr>\
	  <tr>\
	    <td id="messageFunc" align="center" valign="middle" height="110"></td>\
	  </tr>\
	</table>\
    ';
    this.strBox = '\
        <table id="messageBox" width="" border="0" cellpadding="0" cellspacing="0" style="border:0px none;display:none;z-index:999;">\
        	<tr bgcolor="">\
                <td>\
                    <table onselectstart="return false;" style="-moz-user-select:none;" width="100%" border="0" cellpadding="0" cellspacing="0">\
                        <tr>\
                            <td>\
                            <table  width="459px" height="37px" border="0" cellspacing="0" cellpadding="0">\
						      <tr>\
						        <td height="11px" colspan="3" valign="top">&nbsp;</td>\
						      </tr>\
						      <tr>\
						        <td></td>\
						        <td id="messageBoxTitle" valign="bottom" align="center">&nbsp;Message</td>\
						        <td></td>\
						      </tr>\
						    </table>\
                           </td>\
                        </tr>\
                    </table>\
                </td>\
            </tr>\
            <tr id="messageHeight">\
                <td id="messageBody">\
                	<table border="0" cellpadding="0" cellspacing="0">\
                		<tr>\
                			<td rowspan="2">&nbsp;</td>\
                			<td style="height:74px;background:url(../img/messagebox/msg_body.gif) no-repeat;color:#000000;font-family:Arial,Helvetica,sans-serif;font-size:13px;font-weight:bold;">' + this.strBody + '</td>\
                			<td rowspan="2">&nbsp;</td>\
                		</tr>\
                		<tr>\
                			<td class="login_bottom">&nbsp;</td>\
                		</tr>\
                	</table>\
                </td>\
            </tr>\
        </table>\
    ';
    var sffsetTop = 0;
    //var maskWidth = parseInt(document.body.offsetWidth)+20;
    strMask = '<table id="maskbody" width="980px" height="' + document.documentElement.scrollHeight + 'px" border="0" cellpadding="0" cellspacing="0" style="border:0px none;display:none;z-index:998;left:'+ (document.documentElement.offsetWidth-980)/2 +'px;top:0px;"><tr><td></td></tr></table>';
	// check _messageBoxType values,then show deffient Button
	if(_messageBoxType==0)
		strFunc = '<a href="javascript:closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');"><img src="'+path+'msg_box_ok.gif" border="0" /></a>';
		//strFunc = '<div style="padding-top:0px;"/><input id="OK" type="button" style="cursor:pointer;font-family:arial;font-size:16px;width:89px;height:33px;border:0;line-height:20px;background: url('+path+'msg_box_ok.gif); color: #fff;font-weight:bold;" value="'+messageBox_strOk+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
	else if(_messageBoxType==1)
		strFunc = '';
		//strFunc = '<div style="padding-top:6px;"/><input id="OK" type="button" style="cursor:pointer;font-family:arial;font-size:16px;width:89px;height:33px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #fff;font-weight:bold;" value="'+messageBox_strOk+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />&nbsp;&nbsp;&nbsp;&nbsp;<input id="Cancel" type="button" style="cursor:pointer;font-family:arial;font-size:16px;width:89px;height:33px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #fff;font-weight:bold;" value="'+messageBox_strCancel+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
	else if(_messageBoxType==2)
		strFunc = '<div style="padding-top:6px;"/><input id="Continue" type="button"cursor:pointer; style="font-family:arial;font-size:16px;width:89px;height:33px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #fff;font-weight:bold;" value="'+messageBox_strContinue+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />&nbsp;&nbsp;&nbsp;&nbsp;<input id="Cancel" type="button" style="cursor:pointer;font-family:arial;font-size:16px;width:89px;height:33px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #fff;font-weight:bold;" value="'+messageBox_strCancel+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
	else if(_messageBoxType==3)
		strFunc = '';
	else
		strFunc = '<div style="padding-top:6px;"/><input id="OK" type="button" style="cursor:pointer;font-family:arial;font-size:16px;width:89px;height:33px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #fff;font-weight:bold;" value="'+messageBox_strOk+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
    this.init = function(){
        var oDivMask = document.createElement('div');
        oDivMask.id = "mask";
        oDivMask.innerHTML = strMask;
        oDivMask.style.border = "#000000";
        document.body.appendChild(oDivMask);
        var oDiv = document.createElement('span');
        oDiv.id = "messageBoxCase";
        oDiv.innerHTML = this.strBox;
        document.body.appendChild(oDiv);
        if(document.getElementById('messageBoxTitle')!=null){
	    	document.getElementById('messageBoxTitle').innerHTML = title;
	    }
	    document.getElementById('messageMsg').innerHTML = messageContent;
	    document.getElementById('messageFunc').innerHTML = strFunc;
    }
    // show messagebox function
    this.show = function()
    {
    	document.getElementById('messageBodyBox') ? function(){} : this.init();
    	this.middlemask('maskbody');
    	this.middle('messageBox');
    	enableMaskMessage();
    }
    // default show messagebox is middle 
    this.middle = function(_sId){
        $(_sId)['style']['display'] = '';
        $(_sId)['style']['position'] = "absolute";
        $(_sId).style.left = (document.documentElement.clientWidth / 2) -(document.getElementById(_sId).offsetWidth/2)+'px';
        if(browerType.isSafari){
        $(_sId).style.top = (document.documentElement.clientHeight / 2 + document.body.scrollTop)-(document.getElementById(_sId).offsetHeight/2)+'px';
       }else{
        $(_sId).style.top = (document.documentElement.clientHeight / 2 + document.documentElement.scrollTop)-(document.getElementById(_sId).offsetHeight/2)+'px';
       }
        if(document.getElementById('messageBoxTitle')!=null){
        	new Draggable(_sId, {revert:false,handle:'messageBox'});
        }else{
        	new Draggable(_sId, {revert:false,handle:'messageBox'});
        }
    }
    // default show MaskDivTable is middle
    this.middlemask = function(_sId){
        $(_sId)['style']['display'] = "block";
        $(_sId)['style']['position'] = "absolute";
    }
    //reset message transfer by closeMessageBoxBase function
    this.reset = function()
    {
    	//document.getElementById('mask').style.display='none';
    	document.getElementById('messageBoxCase').style.display='none';
    	disableMaskMessage();
    }
    // init messagebox
    this.initData = function(){
	    document.getElementById('messageBoxTitle').innerHTML = title;
	    document.getElementById('messageMsg').innerHTML = messageContent;
	    document.getElementById('messageFunc').innerHTML = strFunc;
    }
}

/* end by open product detail box */

function messageDialog( _title, _messageContent, _messageBoxType, _callbackFuncName, _width, _height)
{
    var title ;
    var messageContent ;
	var type ;
	var callbackFuncName ;
    var sFunc ;
    var sBody ;
    var sBox ;
    var strMask ;
	title = "&nbsp;"+_title;
	messageContent = _messageContent;
	type = _messageBoxType;
	callbackFuncName = _callbackFuncName;
	var titleLen = title.length;
	var messageLen = messageContent.length;
    var width = messageLen*10<500 ? messageLen*10<250 ? 250 : messageLen*10 : 500 ;
    var height = parseInt(messageLen/10)+100 ;
    if(_width!=null && _width!="")
    	width = _width;
    if(_height!=null && _height!="")
    	height = _height;
    //var path = "/mianfeipaibao/app/webroot/img/";
    var path = "/img/";
	var strClose = '<input type="image" id="messageBoxClose" value="Esc" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" src="'+path+'msg_box_cancel.gif" border="0" width="15" height="15"  align="absmiddle" />';

    this.strBody = '\
    <table id="messageBodyBox" width="100%" border="0" cellspacing="0" cellpadding="0" class="msg_box_bg">\
	  <tr>\
	    <td height="23" align="right" style="padding:5px 5px;"><a href=""><a href="javascript:closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');"><img src="'+path+'msg_box_cancel.gif" border="0" /></a></td>\
	  </tr>\
	  <tr>\
	    <td height="130" id="messageMsg" align="center">&nbsp;</td>\
	  </tr>\
	  <tr>\
	    <td id="messageFunc" align="center" valign="middle" height="110"></td>\
	  </tr>\
	</table>\
    ';
    this.strBox = '\
        <table id="messageBox" width="" border="0" cellpadding="0" cellspacing="0" style="border:0px none;display:none;z-index:999;">\
        	<tr bgcolor="">\
                <td>\
                    <table onselectstart="return false;" style="-moz-user-select:none;" width="100%" border="0" cellpadding="0" cellspacing="0">\
                        <tr>\
                            <td>\
                            <table  width="459px" height="37px" border="0" cellspacing="0" cellpadding="0">\
						      <tr>\
						        <td height="11px" colspan="3" valign="top">&nbsp;</td>\
						      </tr>\
						      <tr>\
						        <td></td>\
						        <td id="messageBoxTitle" valign="bottom" align="center">&nbsp;Message</td>\
						        <td></td>\
						      </tr>\
						    </table>\
                           </td>\
                        </tr>\
                    </table>\
                </td>\
            </tr>\
            <tr id="messageHeight">\
                <td id="messageBody">\
                	<table border="0" cellpadding="0" cellspacing="0">\
                		<tr>\
                			<td rowspan="2">&nbsp;</td>\
                			<td style="height:74px;background:url(../img/messagebox/msg_body.gif) no-repeat;color:#000000;font-family:Arial,Helvetica,sans-serif;font-size:13px;font-weight:bold;">' + this.strBody + '</td>\
                			<td rowspan="2">&nbsp;</td>\
                		</tr>\
                		<tr>\
                			<td class="login_bottom">&nbsp;</td>\
                		</tr>\
                	</table>\
                </td>\
            </tr>\
        </table>\
    ';
    var sffsetTop = 0;
    //var maskWidth = parseInt(document.body.offsetWidth)+20;
    strMask = '<table id="maskbody" width="980px" height="' + document.documentElement.scrollHeight + 'px" border="0" cellpadding="0" cellspacing="0" style="border:0px none;display:none;z-index:998;left:'+ (document.documentElement.offsetWidth-980)/2 +'px;top:0px;"><tr><td></td></tr></table>';
	// check _messageBoxType values,then show deffient Button
	if(_messageBoxType==0)
		strFunc = '<a href="javascript:closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');"><img src="'+path+'msg_box_ok.gif" border="0" /></a>';
		//strFunc = '<div style="padding-top:0px;"/><input id="OK" type="button" style="cursor:pointer;font-family:arial;font-size:16px;width:89px;height:33px;border:0;line-height:20px;background: url('+path+'msg_box_ok.gif); color: #fff;font-weight:bold;" value="'+messageBox_strOk+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
	else if(_messageBoxType==1)
		strFunc = '<div style="padding-top:6px;"/><input id="OK" type="button" style="cursor:pointer;font-family:arial;font-size:16px;width:89px;height:33px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #fff;font-weight:bold;" value="'+messageBox_strOk+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />&nbsp;&nbsp;&nbsp;&nbsp;<input id="Cancel" type="button" style="cursor:pointer;font-family:arial;font-size:16px;width:89px;height:33px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #fff;font-weight:bold;" value="'+messageBox_strCancel+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
	else if(_messageBoxType==2)
		strFunc = '<div style="padding-top:6px;"/><input id="Continue" type="button"cursor:pointer; style="font-family:arial;font-size:16px;width:89px;height:33px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #fff;font-weight:bold;" value="'+messageBox_strContinue+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />&nbsp;&nbsp;&nbsp;&nbsp;<input id="Cancel" type="button" style="cursor:pointer;font-family:arial;font-size:16px;width:89px;height:33px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #fff;font-weight:bold;" value="'+messageBox_strCancel+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
	else if(_messageBoxType==3)
		strFunc = '';
	else
		strFunc = '<div style="padding-top:6px;"/><input id="OK" type="button" style="cursor:pointer;font-family:arial;font-size:16px;width:89px;height:33px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #fff;font-weight:bold;" value="'+messageBox_strOk+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
    this.init = function(){
        var oDivMask = document.createElement('div');
        oDivMask.id = "mask";
        oDivMask.innerHTML = strMask;
        oDivMask.style.border = "#000000";
        document.body.appendChild(oDivMask);
        var oDiv = document.createElement('span');
        oDiv.id = "messageBoxCase";
        oDiv.innerHTML = this.strBox;
        document.body.appendChild(oDiv);
        if(document.getElementById('messageBoxTitle')!=null){
	    	document.getElementById('messageBoxTitle').innerHTML = title;
	    }
	    document.getElementById('messageMsg').innerHTML = messageContent;
	    document.getElementById('messageFunc').innerHTML = strFunc;
    }
    // show messagebox function
    this.show = function()
    {
    	document.getElementById('messageBodyBox') ? function(){} : this.init();
    	this.middlemask('maskbody');
    	this.middle('messageBox');
    	enableMaskMessage();
    }
    // default show messagebox is middle 
    this.middle = function(_sId){
        $(_sId)['style']['display'] = '';
        $(_sId)['style']['position'] = "absolute";
        $(_sId).style.left = (document.documentElement.clientWidth / 2) -(document.getElementById(_sId).offsetWidth/2)+'px';
        if(browerType.isSafari){
        $(_sId).style.top = (document.documentElement.clientHeight / 2 + document.body.scrollTop)-(document.getElementById(_sId).offsetHeight/2)+'px';
       }else{
        $(_sId).style.top = (document.documentElement.clientHeight / 2 + document.documentElement.scrollTop)-(document.getElementById(_sId).offsetHeight/2)+'px';
       }
        if(document.getElementById('messageBoxTitle')!=null){
        	new Draggable(_sId, {revert:false,handle:'messageBox'});
        }else{
        	new Draggable(_sId, {revert:false,handle:'messageBox'});
        }
    }
    // default show MaskDivTable is middle
    this.middlemask = function(_sId){
        $(_sId)['style']['display'] = "block";
        $(_sId)['style']['position'] = "absolute";
    }
    //reset message transfer by closeMessageBoxBase function
    this.reset = function()
    {
    	//document.getElementById('mask').style.display='none';
    	document.getElementById('messageBoxCase').style.display='none';
    	disableMaskMessage();
    }
    // init messagebox
    this.initData = function(){
	    document.getElementById('messageBoxTitle').innerHTML = title;
	    document.getElementById('messageMsg').innerHTML = messageContent;
	    document.getElementById('messageFunc').innerHTML = strFunc;
    }
}

//set mask (add function start)
var selectIdArray = new Array();
var objElement;
var intervalHandle ;
var intervalHandleMask ;
var browerType=new function(){
	this.isOpera=(window.opera&&navigator.userAgent.match(/opera/gi))?true:false;
	this.isIE=(!this.isOpera&&document.all&&navigator.userAgent.match(/msie/gi))?true:false;
	this.isSafari=(!this.isIE&&navigator.userAgent.match(/safari/gi))?true:false;
	this.isGecko=(!this.isIE&&navigator.userAgent.match(/gecko/gi))?true:false;
	this.isFirefox=(!this.isIE&&navigator.userAgent.match(/firefox/gi))?true:false;
};
function enableMaskMessage()
{
	getSelectIdArray();
	disableSelect(selectIdArray);
}
function disableMaskMessage()
{
	document.getElementById('mask').style.display='none';
	enableSelect(selectIdArray);
}
function getSelectIdArray()
{
	if(browerType.isIE)
	{
		var allElement = document.getElementsByTagName('SELECT');
		for( i=0,len=allElement.length; i<len; i++)
		{
			if(allElement[i].style.display!='none')
			{
				selectIdArray.push(allElement[i]);
			}
		}
	}
	if(document.getElementById('seminarvideo'))
	{
		var embed = document.getElementById('seminarvideo');
		selectIdArray.push(embed);
	}
}
function disableSelect(objArray)
{
	for(i=0,len=objArray.length; i<len; i++)
	{
		if(objArray[i].id)
		{
			if("seminarvideo"==objArray[i].id)
				objArray[i].style.display='none';
			else
			{
				if(browerType.isIE)
				{
					objArray[i].style.display='none';
				}
			}
		}
		else
		{
			if(browerType.isIE)
			{
				objArray[i].style.display='none';
			}
		}
	}
}
function enableSelect(objArray)
{
	for(i=0,len=objArray.length; i<len; i++)
	{
		if(objArray[i].id)
		{
			if("seminarvideo"==objArray[i].id)
				objArray[i].style.display='';
			else
			{
				if(browerType.isIE)
				{
					objArray[i].style.display='';
				}
			}
		}
		else
		{
			if(browerType.isIE)
			{
				objArray[i].style.display='';
			}
		}
	}
}
function textEditorInitVoke()
{
	getSelectIdArray();
	disableSelect(selectIdArray);
}

function changeImg(imgsrc){
	// + '<a href="javascript:alert(111111);"><img id="zhangxusss" src="'+path+'invitation.gif"></img></a>' + '<a href="javascript:testBenjamin(\''+path+'next.gif\');"><img src="'+path+'next.gif"></img></a>' + '<a href="javascript:testBenjamin(\''+path+'prev.gif\');"><img src="'+path+'prev.gif"></img></a>';
	//alert(imgsrc);
	var imgObj =document.getElementById('productImgId');
	//alert(imgObj.src);
	document.getElementById('productImgId').src = imgsrc;
	
}
//set mask (end)